class Solution(object):
    def isSubtree(self, root, subRoot):
        """
        :type root: TreeNode
        :type subRoot: TreeNode
        :rtype: bool
        """
        def judge(node1, node2):
            if not node1 and not node2:
                return True
            if not node1 or not node2:
                return False
            if node1.val != node2.val:
                return False
            return judge(node1.left, node2.left) and judge(node1.right, node2.right)

        def search(node):
            if node.val == subRoot.val:
                if judge(node, subRoot):
                    return True
            if node.left:
                if search(node.left):
                    return True
            if node.right:
                if search(node.right):
                    return True
            return False

        return search(root)

